package com.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: FanoutConfig
 * Package: com.mq.config
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/8/8 - 14:53
 * @Version: v1.0
 */

/**
 * 声明和创建队列和交换机配置类
 */
@Configuration
public class FanoutConfig {

    /**
     * 自定义交换机
     * @return
     */
    @Bean
    public CustomExchange customExchange()
    {
        Map<String, Object> arguments = new HashMap<>(1);
        //指定交换机类型为：direct
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange("delayed.exchange", "x-delayed-message", true, false,arguments);
    }

    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue queue()
    {
        return QueueBuilder
                .durable("delayed.queue")
                .build();
    }

    /**
     * 绑定
     * @return
     */
    @Bean
    public Binding binding()
    {
        return BindingBuilder.bind(queue()).to(customExchange()).with("delayed-plugin").noargs();
    }
}
